 
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>权限组</title>
    <link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/metro/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/icon.css">
    <link href="../../rs/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="../../rs/plugins/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="../../rs/plugins/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../rs/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="../../rs/js/jquery.cookie.js"></script>
    <script src="../../rs/js/common_qj.js"></script>
    <style>
        html,body{ margin:0px; height:100%;}
    </style>
    <?php
     require_once('login.php');
    ?>
</head>
<body >
<table id="table" class="easyui-datagrid"  style="width:100%;height:100%;padding: 10px;"
       data-options="
			rownumbers:true,
			singleSelect:'false',
			method:'get' ,
			toolbar:'#easyui_toolbar',
			fit:true,
			fitColumns:true">
    <thead>
    <tr>
        <th data-options="field:'ck',checkbox:true"></th>
        <th data-options="field:'mc',align:'center',formatter:formatId,width:30">名称</th>
        <th data-options="field:'bz',align:'center',width:30">备注</th>
        <th data-options="field:'cj_rq',align:'center',width:30">创建日期</th>
    </tr>
    </thead>
</table>

<div id="easyui_toolbar" region="north" border="false"
     style="height: 45px;padding: 5px 5px; ">
    <div style="float: left;">
        <button id="shanchu"  style="float:left; margin-right:5px; border-radius: 0px;height:34px "  class="btn " onclick="data_remove()" >
            <i class="glyphicon glyphicon-trash"></i>
        </button>
    </div>
    <div style="float: left;">
        <button id="xinzeng" style="float:left;margin-left:5px;  border-radius: 0px;" class="btn " onclick="open_modal()"  >
            <i class="glyphicon glyphicon-plus"></i> 新增
        </button>
    </div>
    <div id="tb" class="input-group" style="float: right; margin-right: 10px;width:350px">
        <input type="text" class="form-control" id="searchtext" placeholder="输入搜索关键字" value="">
        <div class="input-group-btn">
            <button type="button" class="btn dropdown-toggle" onclick="do_search()" style="height:34px;border-radius: 0px;">
                搜索
            </button>

        </div>
    </div>
</div>


<div style="display: none" id="open_edit">
    <form id="edit_from">
        <div class="input-group" style="padding: 20px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn   dropdown-toggle " data-toggle="dropdown">名称</button>
            </div>
            <input type="text" class="form-control "   name="mc">
        </div>
        <div class="input-group" style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn   dropdown-toggle " data-toggle="dropdown">备注</button>
            </div>
            <input type="text" class="form-control " name="bz">
        </div>

        <div class="lay_foot">
            <button type="reset" id="reset" style="display:none;">reset</button>
            <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
                    style="background-color: #e2e2e2;" onclick="layer.closeAll()">返回
            </button>
            <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
                    style="background-color: #f54141;color: white;float: right" id="save_do">保存
            </button>
        </div>
    </form>
</div>

<!--页面加载缓冲图标-->
<div id='loadingDiv' style="position:absolute;z-index:1000;top:0px; left:0px;
	width:100%;height:100%;background:white;text-align: center;">
    <h1 style="top: 30%; position: relative;">
        <img src="../../rs/img/loading-2.gif" /><br>
    </h1>
</div>
<script>

    /*页面加载缓冲*/
    function closeLoading() {
        $("#loadingDiv").fadeOut("normal", function () {
            $(this).remove();
        });
    }
    var no;
    $.parser.onComplete = function () {
        if (no) clearTimeout(no);
        no = setTimeout(closeLoading, 1000);
    }
    var sign = URLencode($.cookie('sign'));

    $(function(){
        if(sign==="undefined"){
            window.location.href = "login.html";
        }
        f_sheard();
        sqx();   //设置小权限

        var getdata;
        var row_rid;  //修改行的rid
        var row_index;//更改的行号
    });
    //判断用户权限&加载数据
    function f_sheard(){
        $.ajax({
            type: "post",
            url:G_url+'doi/see/sygr'+"?sign="+sign,
            data: 'sign=' + sign,
            dataType: "json",
            success: function (usedata){
                getdata=usedata;
                if (usedata.ok) {
                    $('#table').datagrid({
                        data: usedata.data
                    });
                }else{
                    window.location.href = 'login.html';
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }
    $("#save_do").on("click",function(){

        var layer_title=$('.layui-layer-title').text();
        var mc=$("input[name='mc']").val();
        var bz=$("input[name='bz']").val();

        if(layer_title=="新增"){
            //if (!f_valid()) return;
            $.ajax({
                type: "post",
                url:G_url+'doi/add/sygr'+'?sign='+sign,
                data:"mc="+mc+"&bz="+bz,
                dataType: "json",
                success: function (result){
                    if (result.ok){
                        var dd=result.data;
                        $('#table').datagrid('appendRow',dd);
                        layer.msg(result.msg);
                    } else {
                        layer.msg(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
            layer.closeAll();

        }else if(layer_title=="修改"){
            $.ajax({
                type: "post",
                url:G_url+'doi/edit/sygr'+'?'+'sign='+sign,
                data:"rid="+row_rid+"&bz="+bz+"&mc="+mc,
                dataType: "json",
                success: function (result){
                    if (result.ok){
                        $('#table').datagrid('updateRow',{
                            index: row_index,
                            row: {
                                mc: mc,
                                bz: bz
                            }
                        });
                        layer.msg(result.msg);
                    } else {
                        layer.msg(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });

            layer.closeAll();
        }
    });
    /*删除操作*/
    function data_remove(){
        var rows = $('#table').datagrid('getSelections');
        if(rows.length!=0){
            layer.msg('确定删除吗？', {
                        time:0,
                        btn: ['确定', '取消'] //按钮
                        ,yes: function do_remove() {
                            var rids = $.map(rows, function (row) {
                                return row.rid
                            });
                            $.ajax({
                                type: "post",
                                url: G_url+'doi/del/sygr'+'?'+'sign='+sign,
                                data:"rid=" + rids,
                                dataType: "json",
                                success: function (result) {
                                    if (result.ok) {
                                        layer.closeAll();
                                        f_sheard();
                                        layer.msg(result.msg);

                                    } else {
                                        layer.msg(result.msg);
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    //alert(errorThrown);
                                }
                            });
                        }
                    }
            );
        }else{
            layer.msg("请先选择！");
        }
    }
    //删除操作




    // 产品搜索操作
    $('#searchtext').bind('keypress',function(event){
        if(event.keyCode == "13") {
            do_search();
        }
    });
    function do_search(){
        var gjc=$('#searchtext').val(); //搜索关键词
        if(gjc==""){
            $('#table').datagrid({
                data: getdata.data
            });
        }else{
            var newdata=[];
            for(var i=0;i<getdata.data.length;i++){
                str=transform(getdata.data[i]).join(',');
                row=str.indexOf(gjc);
                if(row>=0){
                    newdata.push(getdata.data[i]);
                }
            }
            $('#table').datagrid({
                data: newdata
            });
        }
    }
    function transform(obj){
        var arr = [];
        for(var item in obj){
            arr.push(obj[item]);
        }
        return arr;
    }


    function open_modal(){
        sqx_save("新增");
        $("#open_edit").show();
        $('#reset').click();
        layer.open({
            title: "新增",
            type: 1,
            offset: 'rb',
            
            
            area: ['40%', '100%'], //宽高
    				shadeClose: true,
            content: $('#edit_from')
        });
    }

    function open_edit(r){
        sqx_save("修改");
        var rowdata=$('#table').datagrid('getData');
        var row=rowdata.rows[r];
        row_index=r;
        row_rid=row.rid;
        if (row){
            $("#open_edit").show();
            $('#edit_from').form('load',row);
            layer.open({
                title: "修改",
                type: 1,
                offset: 'rb',
                
                
                area: ['40%', '100%'], //宽高
        				shadeClose: true,
                content: $('#edit_from')
            });
        }
    }
    function formatId(value,rowData,rowIndex){
        return "<a href='javascript:void(0)' onclick='open_edit("+rowIndex+");'>"+value+"</a>";
    }


    var f_valid = function(){
        var bh = $.trim($("input[name='bh']").val()) ;
        if( bh =='') {
            layer.msg('请输入用户编号');
            return false;
        }
        var mc = $.trim($("input[name='mc']").val()) ;
        if( mc =='') {
            layer.msg('请输入用户名称');
            return false;
        }
        var sj = $.trim($("input[name='sj']").val()) ;
        if( sj =='') {
            layer.msg('请输入用户手机');
            return false;
        }
        var mm = $.trim($("input[name='mm']").val()) ;
        if( mm =='') {
            layer.msg('请输入密码');
            return false;
        }
        return true;
    };
</script>
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/md5.js"></script>
</body>
</html>
